﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GreatB2C.Config.SiteInfo;

namespace GreatB2C.Web.Manage.SystemSet.SiteInfo
{
    public partial class UploadSet : System.Web.UI.Page
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                LoadSetting( );
            }
        }

        protected void LoadSetting( )
        {
            radlEnableUploadFiles.SelectedValue = UploadConfig.EnableUploadFiles.ToString( );
            txtUploadFileMaxSize.Text = UploadConfig.UploadFileMaxSize.ToString( );
            txtUploadDir.Text = UploadConfig.UploadDir.ToString( );
            txtUploadFileExts.Text = UploadConfig.UploadFileExts.ToString( );
            ddlUploadFilePathRule.SelectedValue = UploadConfig.UploadFilePathRule.ToString( );
            ddlFileNameRule.SelectedValue = UploadConfig.FileNameRule.ToString( );
            txtAdzoneFileType.Text = UploadConfig.AdzoneFileType.ToString( );
            txtAdzoneFilePath.Text = UploadConfig.AuthorFilePath.ToString( );
            txtAuthorFileType.Text = UploadConfig.AuthorFileType.ToString( );
            txtAuthorFilePath.Text = UploadConfig.AuthorFilePath.ToString( );
            txtSourceFileType.Text = UploadConfig.SourceFileType.ToString( );
            txtSourceFilePath.Text = UploadConfig.SourceFilePath.ToString( );
            txtUserFileType.Text = UploadConfig.UserFileType.ToString( );
            txtUserFilePath.Text = UploadConfig.UserFilePath.ToString( );
            txtTrademarkFileType.Text = UploadConfig.TrademarkFileType.ToString( );
            txtTrademarkFilePath.Text = UploadConfig.TrademarkFilePath.ToString( );
            txtProducerFileType.Text = UploadConfig.ProducerFileType.ToString( );
            txtProducerFilePath.Text = UploadConfig.ProducerFilePath.ToString( );
            txtShopFileType.Text = UploadConfig.ShopFileType.ToString( );
            txtShopFilePath.Text = UploadConfig.ShopFilePath.ToString( );
            txtProductstyleFileType.Text = UploadConfig.ProductstyleFileType.ToString( );
            txtProductstyleFilePath.Text = UploadConfig.ProductstyleFilePath.ToString( );
            txtProductmultiplephotoFileType.Text = UploadConfig.ProductmultiplephotoFileType.ToString( );
            txtProductmultiplephotoFilePath.Text = UploadConfig.ProductmultiplephotoFilePath.ToString( );
            txtEmailAttachFileType.Text = UploadConfig.EmailAttachFileType.ToString( );
            txtEmailAttachFilePath.Text = UploadConfig.EmailAttachFilePath.ToString( );
            txtMessageAttachFileType.Text = UploadConfig.MessageAttachFileType.ToString( );
            txtMessageAttachFilePath.Text = UploadConfig.MessageAttachFilePath.ToString( );
            txtBlogFileType.Text = UploadConfig.BlogFileType.ToString( );
            txtBlogFilePath.Text = UploadConfig.BlogFilePath.ToString( );
            txtTaskFileType.Text = UploadConfig.TaskFileType.ToString( );
            txtTaskFilePath.Text = UploadConfig.TaskFilePath.ToString( );
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            bool isSuccess = UploadConfig.Config( radlEnableUploadFiles.SelectedValue.ToString( ) , txtUploadFileMaxSize.Text.Trim( ) , txtUploadDir.Text.Trim( ) , txtUploadFileExts.Text.Trim( )
                , ddlUploadFilePathRule.SelectedValue.ToString( ) , ddlFileNameRule.SelectedValue.ToString( ) , txtAdzoneFileType.Text.Trim( ) , txtAdzoneFilePath.Text
                , txtAuthorFileType.Text.Trim( ) , txtAuthorFilePath.Text.Trim( ) , txtSourceFileType.Text.Trim( ) , txtSourceFilePath.Text.Trim( )
                , txtUserFileType.Text.Trim( ) , txtUserFilePath.Text.Trim( ) , txtTrademarkFileType.Text.Trim( ) , txtTrademarkFilePath.Text.Trim( )
                , txtProducerFileType.Text.Trim( ) , txtProducerFilePath.Text.Trim( ) , txtShopFileType.Text.Trim( ) , txtShopFilePath.Text.Trim( )
                , txtProductstyleFileType.Text.Trim( ) , txtProductstyleFilePath.Text.Trim( ) , txtProductmultiplephotoFileType.Text.Trim( ) , txtProductmultiplephotoFilePath.Text.Trim( )
                , txtEmailAttachFileType.Text.Trim( ) , txtEmailAttachFilePath.Text.Trim( ) , txtMessageAttachFileType.Text.Trim( ) , txtMessageAttachFilePath.Text.Trim( )
                , txtBlogFileType.Text.Trim( ) , txtBlogFilePath.Text.Trim( ) , txtTaskFileType.Text.Trim( ) , txtTaskFilePath.Text.Trim( ) );

            if ( isSuccess )
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "文件上传配置成功！" ) + "&rtn=SystemSet/SiteInfo/UploadSet.aspx" );
            }
            else
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "文件上传配置失败，请联系管理员！" ) + "&rtn=SystemSet/SiteInfo/UploadSet.aspx" );
            }
        }
    }
}
